package com.xxl.job.admin.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryOrderBy;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.dao.XxlJobGroupDao;
import com.xxl.job.admin.service.XxlJobGroupService;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.xxl.job.admin.core.model.table.Tables.XXL_JOB_GROUP;

@Service
public class XxlJobGroupServiceImpl extends ServiceImpl<XxlJobGroupDao, XxlJobGroup> implements XxlJobGroupService {
    @Override
    public List<XxlJobGroup> findByAddressType(int i) {
        QueryWrapper q=QueryWrapper.create().where(XXL_JOB_GROUP.ADDRESS_TYPE.eq(i))
                .orderBy("app_name,title,id ASC");
        return list(q);
    }

    @Override
    public XxlJobGroup load(Integer valueOf) {
        return getById(valueOf);
    }

    @Override
    public void updateGroup(XxlJobGroup group) {
        updateById(group);
    }

    @Override
    public Page<XxlJobGroup> pageList(int start, int length, String appname, String title) {
        QueryWrapper query=QueryWrapper.create()
                .select()
                .from(XXL_JOB_GROUP)
                .where(XXL_JOB_GROUP.APPNAME.like(appname))
                .and(XXL_JOB_GROUP.TITLE.like(title))
                .orderBy(XXL_JOB_GROUP.APPNAME.asc());
        Page<XxlJobGroup> xxlJobGroupPage = mapper.paginate(start,length,query);

        return xxlJobGroupPage;
    }
}
